﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MauiTurntable.dbModel
{
    public class DalItem : dbBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<int> AddData(DBItem data)
        {
            return await helpClass.Database.InsertAsync(data);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public async Task<List<DBItem>> SelectAllData()
        {
            var data = await helpClass.Database.Table<DBItem>().ToListAsync();
            if (data.Count == 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    data.Add(new DBItem()
                    {
                        groupName = "初始化",
                        name = "初始项目"+i,
                        value = i
                    });
                }

            }
            return data;
        }

        public async Task<int> DelectData(long createTimeLong)
        {
            return await helpClass.Database.ExecuteAsync("DELETE FROM DBItem WHERE createTime=" + createTimeLong);
        }
    }
}
